#!/usr/bin/env python
# -*- coding: latin-1 -*-
import sys, os, datetime, platform
from PyQt4.QtGui import QMessageBox,  QApplication

from controlador.principal_controlador import principal_controlador
from conexion import conexion

DEBUG = False

if __name__ == "__main__":
    app = QApplication(sys.argv)
    # Inicio de la conexion a la base de datos
    file = "mascota.db"
    conn = conexion(motor="QSQLITE", dbname=file)
    exists_db = os.path.exists(file)
    if not exists_db: 
        if DEBUG: print "Como no existia la base, se crea y se cargan datos iniciales"
        conn.crearTablas()
        #conn.cargarDatos()
    else:
        dias=['Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo']
        weekdate=dias[datetime.date.today().weekday()]
        if platform.system() == 'Windows':
            comando = "copy "+file+" "+file+".Backup-del-"+str(weekdate)
        else:
            comando = "cp "+file+" mascota.db.Backup-del-"+str(weekdate)
        if DEBUG: print comando
        os.system(comando)
    ui = principal_controlador()
    ui.widget.showMaximized()
    sys.exit(app.exec_())
